<template>
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="请输入名称">
          <el-input v-model="formInline.name" placeholder="请输入配置名称"></el-input>
        </el-form-item>
        <el-form-item label="请输入电话">
          <el-input v-model="formInline.phone" placeholder="请输入配置名称"></el-input>
        </el-form-item>
        <!--        <el-form-item label="注册时间">-->
        <!--          <div class="block">-->
        <!--            <span class="demonstration"></span>-->
        <!--            <el-date-picker v-model="formInline.create_time" type="daterange" value-format="yyyy-MM-dd"-->
        <!--                            range-separator="至"-->
        <!--                            start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>-->
        <!--          </div>-->
        <!--        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
          <el-table-column prop="id" label="ID" width="80"></el-table-column>
          <el-table-column prop="name" label="姓名"></el-table-column>
          <el-table-column prop="phone" label="电话"></el-table-column>
          <el-table-column prop="content" label="反馈内容"></el-table-column>
          <el-table-column prop="create_time" label="反馈时间" width="140"></el-table-column>
          <el-table-column fixed="right" label="状态" >
            
            <template slot-scope="scope">
             <span v-if="scope.row.status == 0" style="color: red;">未读</span>
             <span v-else style="color: blue;">已读</span>
            </template>
          </el-table-column>

          <el-table-column fixed="right" label="操作" >
            <template slot-scope="scope">
              <el-button v-if="scope.row.status == 0"  @click="readClick(scope.row)" type="text" size="small">设置已读
              </el-button>
              <el-button @click="editClick(scope.row)" type="text" size="small">查看详情
              </el-button>
              <el-button @click="deleteClick(scope.row)" type="text" size="small">删除
              </el-button>
              
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
                       :current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper"
                       :total="totalDataNumber"></el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
import FeedBackApi from '@/api/feedback';

export default {
  components: {},
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        name: '',
        phone: '',
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
      /*等级*/
      gradeList: [],
      open_tag: false,
      /*所有标签*/
      allTag: [],
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.formInline;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      FeedBackApi.list(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.totalDataNumber = data.data.list.total;
        })
        .catch(error => {
          self.loading = false;
        });
    },

    /*搜索查询*/
    onSubmit() {
      let self = this;
      self.loading = true;
      let Params = self.formInline;
      self.getTableList();
    },

    /*打开添加*/
    addClick(item) {
      this.$router.push({
        path: '/setting/feedback/edit',
        query: {
          id: 0
        }
      });
    },
    /*打开编辑*/
    editClick(item) {
      let self = this;
      let params = item.id;
      this.$router.push({
        path: '/setting/feedback/edit',
        query: {
          id: params
        }
      });
    },
    /*关闭弹窗*/
    closeDialogFunc(e, f) {
      if (f == 'add') {
        this.open_add = e.openDialog;
        if (e.type == 'success') {
          this.getTableList();
        }
      }
      if (f == 'edit') {
        this.open_edit = e.openDialog;
        if (e.type == 'success') {
          this.getTableList();
        }
      }
    },

    /*删除用户*/
    deleteClick(row) {
      let self = this;
      self
        .$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          self.loading = true;
          FeedBackApi.delete({
              id: row.id
            },
            true
          )
            .then(data => {
              self.loading = false;
              if (data.code == 1) {
                self.$message({
                  message: '恭喜你，删除成功',
                  type: 'success'
                });
                self.getTableList();
              } else {
                self.loading = false;
              }
            })
            .catch(error => {
              self.loading = false;
            });
        })
        .catch(() => {
          self.loading = false;
        });
    },
  

    readClick(row) {
      let self = this;
      self
        .$confirm(' 是否已读?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          self.loading = true;
          FeedBackApi.read({
              id: row.id
            },
            true
          )
            .then(data => {
              self.loading = false;
              if (data.code == 1) {
                self.$message({
                  message: '恭喜你，操作成功',
                  type: 'success'
                });
                self.getTableList();
              } else {
                self.loading = false;
              }
            })
            .catch(error => {
              self.loading = false;
            });
        })
        .catch(() => {
          self.loading = false;
        });
    }
  }
};
</script>
<style></style>
